/*
 * DumpedQueue.java   2008/07/28
 *
 * Copyright 2008 Web & Zen Multimedia, All rights reserved.
 * Use is subject to license terms.
 */
package it.wzm.lightweightlog;


import java.util.LinkedList;
import java.util.Properties;

/**
 * This register has no way of storing passed Entry, which will be immediately passed
 * to the initialized Dumper. Do not use this class with many user access.
 * Useful for debugging purpose or for single user application.
 * @author Leonardo Celati
 * @param <E> any valid extension to Entry
 */
public class DumpedQueue<E extends Entry> extends Queue<E> implements NotCumulable {
    
    /**
     * Default initializer
     */
    DumpedQueue(Properties p) {
    	super(p);
    }
    
    /**
     * This will always return true
     * @return true
     */
    @Override
    boolean isEmpty() {
        return true;
    }
    
    /**
     * This will always return null
     * @return Always null
     */
    @SuppressWarnings("unchecked")
    public LinkedList<E> retainAll() {
        return (LinkedList<E>)null;
    }
    
    /**
     * This method will in turn call the dump method
     * @param e Anything extending Entry
     * @return True if this Entry it's correctly added
     * @see it.wzm.lightweightlog.Queue#push(it.wzm.lightweightlog.Entry)
     */
    @Override
    boolean push(E e) {
        try {
            this.dump(e);
        } catch (DumperException e1) {
            return false;
        }
        return true;
    }
    
    /**
     * Always return 0
     * @return 0
     */
    @Override
    int size() {
        return 0;
    }
    
    /**
     * Pass the Entry to saved Dumper
     * @param t Anything extending Entry
     * @throws it.wzm.lightweightlog.DumperException If something went wrong
     */
    public <T extends Entry> void dump(T t) throws DumperException {
        // first we get the register
        ObjectFactory.getRegister().dispatchToDumper(t);
    }
    
}
